import { ref, computed } from "vue";
import { defineStore } from "pinia";

export const useInfoStore = defineStore("info", () => {
  const user = ref(null);

  const setUser = (data) => {
    console.log(data);
    user.value = data;
    localStorage.setItem("user", JSON.stringify(data));
  };
  const isLogin = computed(() => {
    return user.value !== null;
  });

  setUser(
    localStorage.getItem("user") && JSON.parse(localStorage.getItem("user"))
  );

  return {
    user,
    setUser,
    isLogin,
  };
});
